<?php
header('content-type:text/html;charset=utf8');
use wepay\join\demo\common\Bankele;//引用四要素文件
/**
 * Class UserController
 */
class UserController extends BaseController
{

    /**
     * 构造函数
     *
     * @access   public
     * @return   void
     */
    public function __construct(){
        parent::__construct();
        //权限控制
        $info = session_get(UserEnum::USER_INFO_SESSION_KEY);
        if(empty($info)){

            echo "<script>alert('你还没有登录,请重新登录');location='/login';</script>";

            //      echo"<script>Showbo.Msg.nameauth('你还没有登录,请重新登陆',function(){
            //      location='/login';
            // })</script>";

        }
    }

    /**
     * 账户信息
     * @return mixed
     */
    public function UserAccount()
    {
        $info = UserService::instance()->UserAccount();
        $chart = UserService::instance()->UserAccountChart();
        if(!empty($chart)){
            $chart = json_encode($chart);
            $chart = json_decode($chart,true);
            $arr = array();
            foreach($chart as $k=>$v){
                for($i=1;$i<=12;$i++) {
                    if ($v['month'] == $i) {
                        $arr[$v['year']][]= $v['month'];
                    }
                }
            }
            $arr2 = array();
            for($i = 1; $i <= 12; $i++) {
                $info2[$i] = 0;
            }
            foreach($arr as $k=>$v) {
                $arr2[$k] = $info2;
                foreach ($v as $kk => $vv) {
                    $arr2[$k][$vv] = intval($chart[$kk]['wait_money']);
                }
                $data[$k]['data'] = array_values($arr2[$k]);
            }
            $data = json_encode($data);

        }else{
            $year = date('Y',time());
            $data[$year]['data']=array(0,0,0,0,0,0,0,0,0,0,0,0);
            $data = json_encode($data);
        }
        $datpende   =UserService::instance()->UserAccountpende();//投资收益中的金额
        //现金券总数
        // $withdraw = UserService::instance()->voucher();
        // print_r($withdraw);
        $vouchersta    = UserService::instance()->vouchersta();//现金卷是否过期，修改staue状态
        $vouchersum    = UserService::instance()->vouchersum();//没过期现金卷总数
      return $this->view('index.user_account')->with(['info'=>$info,'datpende'=>$datpende,'vouchersum'=>$vouchersum,'data'=>$data]);
    }

    /**
     * 折线图信息
     * @return mixed
     */
    public function LineChart()
    {

        $data = UserService::instance()->LineChart();
        if(!empty($data)){
            $data = json_encode($data);
            $data = json_decode($data,true);
            $end = date('Y',time());
            $arr = array();
            for($i=2012;$i<=$end;$i++){
                foreach($data as $k=>$v){
                    if($v['year'] == $i){
                        $arr[$i][] = $v;
                        unset($data[$k]);
                    }
                }
            }
            $arr2 = array();
            foreach($arr as $k=>$v){
                foreach($v as $kk=>$vv){
                    for($i=1;$i<=12;$i++) {
                        if ($vv['month'] == $i) {
                            $arr2[$vv['year']][]= $vv['month'];
                        }
                    }
                }
            }

            $arr4 = array();
            foreach($arr2 as $key=>$val){
                $arr4[] = $key;
            }
            $min = min($arr4);

            $arr3 = array();
            for($i = 1; $i <= 12; $i++) {
                $info[$i] = 0;
            }
            foreach($arr2 as $k=>$v) {
                $arr3[$k] = $info;
                $arr3[$min-1]=$info;
                foreach ($v as $kk => $vv) {
                    $arr3[$k][$vv] = intval($arr[$k][$kk]['wait_money']);
                }
                $data[$min-1]['data'] = array(0,0,0,0,0,0,0,0,0,0,0,0);
                $data[$k]['data'] = array_values($arr3[$k]);
            }

            return json_encode($data);
        }else{
            $year = date('Y',time());
            $data[$year]['data']=array(0,0,0,0,0,0,0,0,0,0,0,0);
            return json_encode($data);
        }


    }


    /**
     * 实名认证
     * @return mixed
     */
    public function UsernameAuthOne()
    {

        //session_get(UserEnum::USER_INFO_SESSION_KEY);
        return $this->view('index.username_auth_one');
    }

    public function RealNameAuth()
    {
        if(Request::isMethod('post')){
            #收集信息
            $paramObj = new stdClass();
            $paramObj->real_name            =       $this->getParam('real_name');
            $paramObj->id_card              =       $this->getParam('id_card');


            #逻辑处理
            $rs = UserService::instance()->RealNameAuth($paramObj);
            return $rs;
;
        }
    }

    public function UsernameAuthTwo()
    {
        if(Request::isMethod('post')){
            #收集信息
            $paramObj = new stdClass();
            $paramObj->real_name            =       $this->getParam('real_name');
            $paramObj->id_card              =       $this->getParam('id_card');

            Session::put('real_name',$paramObj->real_name);
            Session::put('id_card',$paramObj->id_card);
        }

        $real_name = Session::get('real_name');
        $id_card   = Session::get('id_card');
        if(!empty($real_name)&&!empty($id_card)){
            return $this->view('index.username_auth_two')->with(['real_name'=> $real_name,'id_card'=> $id_card]);
        }else{
            return $this->view('index.username_auth_two');
        }


    }

    public function UsernameAuthThr()
    {
        if(Request::isMethod('post')){
            #收集信息
            $paramObj = new stdClass();
            $paramObj->pay_pwd                   =       $this->getParam('pay_pwd');
            $paramObj->real_name                 =       $this->getParam('real_name');
            $paramObj->id_card                   =       $this->getParam('id_card');

            #逻辑处理
            $rs = UserService::instance()->UsernameAuthThr($paramObj);
            if($rs){
                Session::forget('real_name');
                Session::forget('id_card');
                return $this->view('index.username_auth_thr');
            }

        }

    }



    /**
     * 银行卡管理
     * @return mixed
     */
    public function UserBankcard()
    {


        $info = UserService::instance()->UserBankcard();
        return $this->view('index.user_bankcard')->with('info',$info);
    }

    /**
     * 添加银行卡
     * @return mixed
     */
    public function UserBankcardAdd()
    {
        return $this->view('index.user_bankcard_add');
    }

    /**
     * 银行卡编辑
     * @return mixed
     */
    public function UserBankcardUp()
    {
        $bank_id = $this->getParam('bank_id');
        $user_bank = UserService::instance()->UserBankcardUp($bank_id);
        return $this->view('index.user_bankcard_add')->with('user_bank',$user_bank);
    }
    /**
     * 绑定银行卡
     * @return mixed
     */
    public function UserBankcardBound()
    {
        if(Request::isMethod('post')){
            #收集信息
            $paramObj = new stdClass();
            $paramObj->bank_id              =        $this->getParam('bank_id');
            $paramObj->bank_num             =        $this->getParam('bank_num');
            $paramObj->bank_name            =        $this->getParam('bank_name');
            $paramObj->bound_mobile         =        $this->getParam('bound_mobile');
            $paramObj->kaihuhang            =        $this->getParam('kaihuhang');
            $paramObj->bound_name           =        $this->getParam('bound_name');
            $paramObj->province             =        $this->getParam('province');
            $paramObj->city                 =        $this->getParam('city');
            $paramObj->area                 =        $this->getParam('area');
            $paramObj->bank_code            =        $this->getParam('bank_code');
            $paramObj->id_card              =        $this->getParam('id_card');
            $paramObj->verify               =        $this->getParam('verify');
            $paramObj->token                =        $this->getParam('token');
            $v_id                           =        $this->getParam('v_id');
            #逻辑处理

            $user_id  = session_get(UserEnum::USER_INFO_USER_ID);
            $bank = UserService::instance()->GetBankInfo($user_id);
            $auth=UserService::instance()->BankAuth($paramObj,$v_id);
            if(!empty($paramObj->verify)){
                if($auth['data']['resultCode']==000&&$auth['data']['resultInfo']=='0元身份认证成功')
                {
                    if(empty($paramObj->bank_id)){
                        if(!$bank&&empty($paramObj->bank_id)){
                            $asd=UserService::instance()->UserBankcardBound($paramObj);
                            if($asd>0){
                                echo "<script>alert('绑定成功');window.location.href='/user_bankcard';</script>";
                            }else{
                                echo "<script>alert('绑定失败，请重新绑定');window.location.href='/user_bankcard_add';</script>";
                            }
                        }else{
                            echo "<script>alert('已经绑定银行卡');window.location.href='/user_bankcard';</script>";
                        }
                    }else{
                        $asd = UserService::instance()->UserBankcardUpdata($paramObj);
                        if($asd>0){
                            echo "<script>alert('修改银行卡信息成功');window.location.href='/user_bankcard';</script>";
                        }else{
                            echo "<script>alert('修改失败，请重新修改银行卡信息');window.location.href='/user_bankcard_add';</script>";
                        }
                    }
                }
                if($auth['data']['resultCode']=="BEB_003"||$auth['data']['resultCode']=="BEPN_002"){
                    echo "<script>alert('短信验证码错误或失效');window.location.href='/bank_card?token=".$paramObj->token."&bank_id=".$paramObj->bank_id.
                        "&id_card=".$paramObj->id_card."&bank_code=".$paramObj->bank_code."&bank_num=".$paramObj->bank_num."&bank_name=".$paramObj->bank_name.
                        "&kaihuhang=".$paramObj->kaihuhang."&bound_mobile=".$paramObj->bound_mobile."&province=".$paramObj->province.
                        "&city=".$paramObj->city."&area=".$paramObj->area."&bound_name=".$paramObj->bound_name."'</script>";
                }
                if($auth['error']==1){
                    echo "<script>alert('信息有误,请重新绑定');window.location.href='/user_bankcard_add</script>";
                }
            }else{
                return $auth;
            }
        }
    }

    /**
     * 银行卡解绑验证
     * @return int
     */
    public function CheckBankPay(){
        #收集信息
        $paramObj = new stdClass();
        $paramObj->bank_id = $this->getParam('bank_id');
        $paramObj->pay_pwd = $this->getParam('pay_pwd');

        if(!empty($paramObj->pay_pwd)){
            $rs = UserService::instance()->CheckBankPay($paramObj->pay_pwd);
            if($rs){
                return 1;
            }
        }
    }
    /**
     * 银行卡解绑
     * @return mixed
     */
    public function UserBankcardUnbound()
    {

        #收集信息
        if(Request::isMethod('post')){
            $paramObj = new stdClass();
            $paramObj->bank_id = $this->getParam('bank_id');
            $paramObj->pay_pwd = $this->getParam('pay_pwd');
            return  UserService::instance()->UserBankcardUnbound($paramObj);
        }
    }
    /**
     * 银行卡解绑ajax返回
     * @return mixed
     */
    public function BankcardUnboundAjax()
    {
        $info = UserService::instance()->UserBankcard();
        return $this->viewAjax('index.ajaxTemplates.user_bankcard_part')->with('info', $info);
    }

    /**
     * 密码管理
     * @return mixed
     */
    public function UserPassword()
    {
        return $this->view('index.user_password');
    }

    /**
     * 登录密码修改
     */
    public function UpLoginPwd()
    {
        if (Request::isMethod('post')) {
            #收集信息
            $paramObj = new stdClass();
            $paramObj->now_pwd           =       $this->getParam('now_pwd');
            $paramObj->new_pwd           =       $this->getParam('new_pwd');
            $paramObj->captcha           =       $this->getParam('captcha');

            #逻辑处理
            try{
                $data = UserService::instance()->UpLoginPwd($paramObj);
                Session::flush();
                echo "<script>alert('修改成功,请重新登陆');location.href='/login'</script>";
            }catch(Exception $e){
                print_R($e->getMessage());
            }

        }
    }

    /**
     * js登录密码修改
     * @return int
     */
    public function JsUpLoginPwd()
    {
        if (Request::isMethod('post')) {
            #收集信息
            $paramObj = new stdClass();
            $paramObj->now_pwd           =       $this->getParam('now_pwd');
            $paramObj->captcha           =       $this->getParam('captcha');

            if(!empty($paramObj->now_pwd)){
                $data =  UserService::instance()->CheckNowPwd($paramObj);
                $rs = empty($data)?0:1;
                return $rs;
            }
            if(!empty($paramObj->captcha)){
                if(strtolower($paramObj->captcha) == strtolower(Session::get('ypt_Captcha'))){
                    return 1;
                }
            }
        }
    }
    /**
     * 支付密码修改
     */
    public function UpPayPwd()
    {
        if (Request::isMethod('post')) {
            #收集信息
            $paramObj = new stdClass();
            $paramObj->mobile                 =       $this->getParam('mobile');
            $paramObj->news_captcha           =       $this->getParam('news_captcha');
            $paramObj->pay_captcha            =       $this->getParam('pay_captcha');
            $paramObj->pay_new_pwd            =       $this->getParam('pay_new_pwd');

            #逻辑处理
            try{
                UserService::instance()->UpPayPwd($paramObj);
                return Redirect::to('/user_account');
            }catch(Exception $e){
                print_R($e->getMessage());
            }

        }
    }

    /**
     * js支付密码修改
     * @return int
     */
    public function JsUpPayPwd()
    {
        if (Request::isMethod('post')) {
            #收集信息
            $paramObj = new stdClass();
            $paramObj->news_captcha           =       $this->getParam('news_captcha');
            $paramObj->pay_captcha            =       $this->getParam('pay_captcha');

            if(!empty($paramObj->news_captcha)){
                $news =session_get(UserEnum::CLIENT_NEWS_CAPTCHA);
                $time =time()-$news['time'];
                if($time<=600){
                    if($paramObj->news_captcha== $news['news_captcha']){
                        return 1;
                    }
                }
            }
            if(!empty($paramObj->pay_captcha)){
                if(strtolower($paramObj->pay_captcha) == strtolower(Session::get('ypt_Captcha'))){
                    return 1;
                }
            }
        }
    }

    /**
     * 充值
     * @return mixed
     */
    public function UserMoney()
    {

        $info = UserService::instance()->GetBankManageOne();//查找用户的银行卡
        //print_r($info);
        $infoyeno = UserService::instance()->GetBankManageyeno();//查找是否已经绑定银行卡
        //获取实名认证完的ID
        $infocf = UserService::instance()->Certificate();//查找是否认证
        //print_r($infocf);
        //获取实名认证完的ID
        $infoname = UserService::instance()->Certificatename();//查找是否认证
          //体现金额
        $UserExtendone  = UserService::instance()->UserExtendone();//可用余额
        return $this->view('index.user_money')->with(['info'=>$info,'infoyeno'=> $infoyeno,'infocf'=> $infocf,'infoname'=>$infoname,'UserExtendone'=>$UserExtendone]);
    }


    /**
     * 绑定银行卡短信验证
     * @return int
     */
    public function UserMoneyNews(){
        if (Request::isMethod('post')) {
            #收集信息
            $paramObj = new stdClass();
            $paramObj->news_captcha           =       $this->getParam('news_captcha');

            if(!empty($paramObj->news_captcha)){
                $news =session_get(UserEnum::CLIENT_NEWS_CAPTCHA);
                if($paramObj->news_captcha== $news['news_captcha']){
                    return 1;
                }
            }
        }
    }
    /**
     * 快捷卡提交动作
     * @return mixed
     */

    public function AjaxUserMoney()
    {
        #收集信息
        $paramObj = new stdClass();
        $paramObj->myselect             =       $this->getParam('myselect');//银行名字
        $paramObj->yinhang              =       $this->getParam('yinhang');//银行卡
        $paramObj->phone                =       $this->getParam('phone');//手机号
        $paramObj->bank_code            =       $this->getParam('bank_code');//银行缩写
        $paramObj->realname             =       $this->getParam('realname');//名字
        $paramObj->id_card              =       $this->getParam('id_card');
        $paramObj->verify              =       $this->getParam('verify');
        $bankeleobj = new bankele();
        if(empty($paramObj->verify)){
            $token=$bankeleobj->getToken(); //'SbdzQR2ja0d7FkxdgqjHarmau8DrbD83ck58QrWnIEg=';//
            $result=$bankeleobj->auth($paramObj->realname,$paramObj->id_card,$paramObj->yinhang,$paramObj->bank_code,$paramObj->phone,$token);
            if($result['data']['resultCode']=='000')
            {
                $result['token'] = $token;
                $result['code']   = '1';
                $result['mess']   = '发送短信成功';
                $result['url']   = "/user_quick__card?xunms=$token&bank_code=$paramObj->bank_code&yinhang=$paramObj->yinhang&myselect=$paramObj->myselect";
                return $result;
            }else{
                $result['token'] = "";
                $result['code']   = '2';
                $result['mess']   = '发送短信失败';
                return $result;
            }
        }else{
            $token= $this->getParam('token');//银行名字 SbdzQR2ja0d7FkxdgqjHarmau8DrbD83gnkcYnVyP Q=
            $result=$bankeleobj->confirm($paramObj->realname,$paramObj->id_card,$paramObj->yinhang,$paramObj->bank_code,$paramObj->phone,$token,$paramObj->verify);
            if($result['error']==0){
                $result['code']   = '1';
                $result['mess']   =$result['message'];
                $result['url']   = "/user_money";
                $info = UserService::instance()->UserMoneyajax($paramObj);
                return $result;
            }elseif($result['error']==1){
                $result['token'] = "";
                $result['code']   = '2';
                $result['mess']   = $result['message'];
                return $result;
            }
        }
    }

    /**
     *快捷卡发送短信跳转页面
     */
    public function UserQuickcard(){
        $asda=session_get(UserEnum::USER_INFO_SESSION_KEY);
        $info = UserService::instance()->Certificatename();
//            print_r($info);
//            die;
        $paramObj = new stdClass();
        $paramObj->token            =       $this->getParam('xunms');//Token
        $paramObj->bank_code        =       $this->getParam('bank_code');//银行卡
        $paramObj->yinhang             =       $this->getParam('yinhang');//手机号
        $paramObj->myselect             =       $this->getParam('myselect');//手机号
        return $this->view('index.user_quickcard')->with(['info'=>$info,'param'=>$paramObj]);
    }

    /**
     *重新获取验证码
     */
    public function CodeNews(){
        #收集信息
        $paramObj = new stdClass();
        $paramObj->myselect             =       $this->getParam('myselect');//银行名字
        $paramObj->yinhang              =       $this->getParam('yinhang');//银行卡
        $paramObj->phone                =       $this->getParam('phone');//手机号
        $paramObj->bank_code            =       $this->getParam('bank_code');//银行缩写
        $paramObj->realname             =       $this->getParam('realname');//名字
        $paramObj->id_card              =       $this->getParam('id_card');
        $paramObj->token              =       $this->getParam('token');
        $bankeleobj = new bankele();
        $result=$bankeleobj->auth($paramObj->realname,$paramObj->id_card,$paramObj->yinhang,$paramObj->bank_code,$paramObj->phone,$paramObj->token );
        if($result['data']['resultCode']=='000')
        {
            $result['code']   = '1';
            $result['mess']   = '发送短信成功';
            return $result;
        }else{
            $result['token'] = "";
            $result['code']   = '2';
            $result['mess']   = '发送短信失败';
            return $result;
        }

    }

    /**
     * 短信验证
     * @return string
     */
    public function VerifyNews()
    {
        if(Request::isMethod('POST')){
            #接收参数
            $paramObj = new stdClass();
            $paramObj->mobile            =       $this->getParam('mobile');                  //联系方式

            if(!empty($paramObj->mobile))
            {
                $data = IndexService::instance()->VerifyNews($paramObj);
                if ($data) {
                    return('{"success":true,"msg":"发送短信成功!."}');
                }else{
                    return('{"success":false,"msg":"发送短信成功！."}');


                }
            }
        }
    }
    /**
     * 提现
     * @return mixed
     */
    public function UserMoney_()
    {
        $infocf         = UserService::instance()->Certificate();//是否认证
        $card           =$infocf->id_card;
        // print_r($card);
        $info           = UserService::instance()->GetBankManageOne();//查找用户的银行卡信息
        $infoyeno       = UserService::instance()->GetBankManageyeno();//查找是否已经绑定银行卡
        //体现金额
        $UserExtendone  = UserService::instance()->UserExtendone();//可用余额
        return $this->view('index.user_money_')->with(['card'=>$card,'info'=>$info,'infoyeno'=>$infoyeno,'UserExtendone'=> $UserExtendone]);
    }
    /**
     * 提现动作
     * @return mixed
     */
    public function AjaxUserMone(){
        if(Request::isMethod('POST')){
            if(!get_magic_quotes_gpc()){//防sql
                $paramObj = new stdClass();
                $paramObj->bank_num         =addslashes($this->getParam('bank_num'));
                $paramObj->bound_name       =addslashes($this->getParam('bound_name'));
                $paramObj->moneysum         =addslashes($this->getParam('moneysum'));
                $paramObj->pay_pwd          =addslashes($this->getParam('pay_pwd'));
            }else{
                $paramObj = new stdClass();
                $paramObj->bank_num         =$this->getParam('bank_num');
                $paramObj->bound_name       =$this->getParam('bound_name');
                $paramObj->moneysum         =$this->getParam('moneysum');
                $paramObj->pay_pwd          =$this->getParam('pay_pwd');
            }
            $info = UserService::instance()->AjaxWithdraw($paramObj);
            //print_r($info);
            return $info;
        }

    }
    public function UserMoneyPay()
    {   

        if(Request::isMethod('POST')){
        $moneysum       =   $this->getParam('moneysum');
        $bank_num       =   $this->getParam('bank_num');
        $bound_name     =   $this->getParam('bound_name');
         // print_r($paramObj);
        if (empty($moneysum)||empty($bank_num)||empty($bound_name)){
            $mess['code'] = '2';
            $mess['mess'] = '参数错误！！!';
             return $mess;
        }else{
            $mess['code'] = '1';
            $moneysum   =UserService::instance()->UserMoneyjiami($moneysum);
            $bank_num   =UserService::instance()->UserMoneyjiami($bank_num);
            $bound_name =UserService::instance()->UserMoneyjiami($bound_name);
            $mess['url'] = "/user_money_pay?xunms=$moneysum&siuccsed=$bank_num&fession=$bound_name";
            return $mess;
        }
     }else{
        $paramObj = new stdClass();
        $paramObj->moneysum       =   UserService::instance()->UserMoneyjiamis($this->getParam('xunms'));
        $paramObj->bank_num       =   UserService::instance()->UserMoneyjiamis($this->getParam('siuccsed'));
        $paramObj->bound_name     =   UserService::instance()->UserMoneyjiamis($this->getParam('fession'));

        return $this->view('index.user_money_pay')->with('info',$paramObj);

     }
       
    }
    /**
     *提现成功页面
     */
    public  function UserMoneySuccess(){
        return $this->view('index.user_money__success');
    }


    // /**
    //  * 提现支付密码
    //  * @throws Exception
    //  */
    // public function WithdrawPwd()
    // {
    //     $paramObj = new stdClass();
    //     $paramObj->pay_pwd        =   $this->getParam('pay_pwd');
    //     $paramObj->bank_num       =   $this->getParam('bank_num');
    //     $paramObj->bound_name     =   $this->getParam('bound_name');
    //     $paramObj->moneysum       =   $this->getParam('moneysum');


    //     $data  = UserService::instance()->WithdrawPwd($paramObj);
    //     if($data==1){
    //         return Redirect::To('/user_money__success');
    //     }
    // }
    // public function JsWithdrawPwd()
    // {
    //     $pay_pwd = $this->getParam('pay_pwd');
    //     return UserService::instance()->JsWithdrawPwd($pay_pwd);
    // }
    /**
     * 账户明细
     * @return mixed
     */
    public function UserAccountDetails()
    {
        $account = UserService::instance()->Account();
        return $this->view('index.user_account_details')->with(['account'=>$account]);

    }
    /**
     * 充值记录
     * @return mixed
     */
    public function UserRechargeRecord()
    {
        $recharge = UserService::instance()->Recharge();
        return $this->view('index.user_recharge_record')->with(['recharge'=>$recharge]);

    }
    /**
     * 提现记录
     * @return mixed
     */
    public function UserWithdrawRecord()
    {
        $withdraw = UserService::instance()->Withdraw();
        return $this->view('index.user_withdraw_record')->with(['withdraw'=>$withdraw]);

    }


    /**
     * 平台奖励
     * @return mixed
     */
    public function UserAward()
    {
        $experience     = UserService::instance()->experience();//体验金
        $experiences    = UserService::instance()->experiencesta();//体验金是否过期，查看staue状态
        $experiencesum  = UserService::instance()->experiencesum();//体验金查看没有过期的总数
        $experiencemoney  = UserService::instance()->experiencemoney();//计算收益
        //print_r(date('Y-m-d',1465190190 ));
        // print_r(expression);

        //现金劵
        $withdraw = UserService::instance()->voucher();
        $vouchersta    = UserService::instance()->vouchersta();//现金卷是否过期，修改staue状态
        //print_r($withdraw);
        return $this->view('index.user_award')->with(['withdraw'=>$withdraw,'experience'=>$experience,'experiencesum'=>$experiencesum,'experiencemoney'=>$experiencemoney]);
    }


    /**
     * 邀请好友
     * @return mailparse_determine_best_xfer_encoding(fp)
     */
    public function UserInvite()
    {
        //邀请链接
        $rh = UserService::instance()->UserInvite();//加密uid
        $urlpash=$_SERVER['HTTP_HOST'];
        $url="http://$urlpash/register?id=$rh";
        //邀请链接
        $reward = UserService::instance()->Reward();//列表
        // return  $reward;
        $sum = UserService::instance()->Rewardsum();//总金额
        $count = UserService::instance()->Rewardcount();//总人数
        return $this->view('index.user_invite')->with(['url'=>$url,'reward'=>$reward,'sum'=>$sum,'count'=>$count]);

    }

    /**
     * 投资记录
     * @return mixed
     */
    public function UserInvestTicket()
    {

        if(Request::isMethod('POST')) {
            #接收参数
            $paramObj = new stdClass();
            $paramObj->year1             =       $this->getParam('year1');                   //年
            $paramObj->month1            =       $this->getParam('month1');                  //月
            $paramObj->p_type            =       $this->getParam('p_type');                  //项目类别
            $paramObj->page              =       $this->getParam('page');                    //分页
            if(empty($paramObj->page)){
                $paramObj->page =1;
            }
            $info = UserService::instance()->UserInvestTicket($paramObj);
            return $info;
        }else{
            $datanum    =UserService::instance()->InvestTicketnum();//投资金额
            $datagains  =UserService::instance()->InvestTicketgains();//投资收益完成的
            $datpende   =UserService::instance()->InvestTicketpende();//投资收益中的金额

            $paramObj = new stdClass();
            $paramObj->year1    =   date('Y',time());
            $paramObj->month1   =   date('n',time());
            $paramObj->page     =   1;
            $paramObj->p_type   =   1;
            $info       =UserService::instance()->UserInvestTicket($paramObj);
            return $this->view('index.user_invest_ticket')->with(['info'=>$info,'datanum'=>$datanum,'datagains'=>$datagains,'datpende'=>$datpende]);
        }


    }


    /**
     * 投资记录分页
     */
    public function UserInvestPage()
    {

        $paramObj = new stdClass();
        $paramObj->year1             =       $this->getParam('year');                   //年
        $paramObj->month1            =       $this->getParam('month');                  //月
        $paramObj->p_type            =       $this->getParam('p_type');                 //项目类别
        $paramObj->page              =       $this->getParam('page');                   //分页


        if(!empty($paramObj->year1)||!empty($paramObj->p_type))
        {
            $pagelist = UserService::instance()->UserInvestTicket($paramObj);
            return $this->rest->success(['state' => $pagelist ]);
        }else{
            $page = $this->getParam('page');
            $pagelist = UserService::instance()->UserInvestTicket($page);
            return $this->rest->success(['state' => $pagelist ]);
        }
    }


    /**
     * 报票记录
     * @return mixed
     */
    public function UserBTicket()
    {
        $info = UserService::instance()->UserBTicket();
        return $this->view('index.user_b_ticket')->with('info',$info);
    }

    /**
     * 消息列表
     * @return mixed
     */
    public function UserNewsList()
    {
        $info =UserService::instance()->ReadAllPage(1);
        $all = UserService::instance()->ReadAll();
        $unread = UserService::instance()->Unread();
        return $this->view('index.user_news_list')->with(['all'=>$all,'info'=>$info,'unread'=>$unread]);

    }
    public function UserNewsList_()
    {

        $info =UserService::instance()->UnReadPage(1);
        $all = UserService::instance()->ReadAll();
        $unread = UserService::instance()->Unread();
        return $this->view('index.user_news_list_')->with(['all'=>$all,'info'=>$info,'unread'=>$unread]);

    }
    public function UserNewsList__()
    {
        $info =UserService::instance()->ReadPage(1);
        $all = UserService::instance()->ReadAll();
        $unread = UserService::instance()->Unread();
        return $this->view('index.user_news_list__')->with(['all'=>$all,'info'=>$info,'unread'=>$unread]);

    }
    public function AllNewsPage()
    {
        $page = $this->getParam('page');
        $pagelist = UserService::instance()->ReadAllPage($page);
        return $this->rest->success(['state' => $pagelist ]);
    }

    public function UnreadNewsPage()
    {
        $page = $this->getParam('page');
        $pagelist = UserService::instance()->UnReadPage($page);
        return $this->rest->success(['state' => $pagelist ]);

    }
    public function ReadNewsPage()
    {
        $page = $this->getParam('page');
        $pagelist = UserService::instance()->ReadPage($page);
        return $this->rest->success(['state' => $pagelist ]);
    }

    public  function UserNewsDel1()
    {
        #收集信息
        $paramObj = new stdClass();
        $paramObj->num  = $this->getParam('num');

        #逻辑操作
        UserService::instance()->UserNewsDel($paramObj);
        $info = UserService::instance()->ReadAllPage(1);
        return $info;
    }

    public function UserNewsDel2()
    {
        #收集信息
        $paramObj = new stdClass();
        $paramObj->num  = $this->getParam('num');

        #逻辑操作
        UserService::instance()->UserNewsDel($paramObj);
        $info = UserService::instance()->UnReadPage(1);
        return $info;

    }

    public function UserNewsDel3()
    {
        #收集信息
        $paramObj = new stdClass();
        $paramObj->num  = $this->getParam('num');

        #逻辑操作
        UserService::instance()->UserNewsDel($paramObj);
        $info = UserService::instance()->ReadPage(1);
        return $info;

    }

    /**
     * 未读修改
     */
    public function UserNewsUp()
    {
    echo(11111);
        $m_id = $this->getParam('m_id');
        print_R(1);die;
        print_R($m_id);die;
        UserService::instance()->UserNewsUp($m_id);
    }

    public function BankAuth()
    {
        $info = UserService::instance()->BankAuth();
        return $info;
    }

    /**
     * 短信验证
     * @return mixed
     */
    public function BankCard()
    {
            #收集信息
            $paramObj = new stdClass();
            $paramObj->bank_id              =        $this->getParam('bank_id');
            $paramObj->bank_num             =        $this->getParam('bank_num');
            $paramObj->bank_name            =        $this->getParam('bank_name');
            $paramObj->bound_mobile         =        $this->getParam('bound_mobile');
            $paramObj->kaihuhang            =        $this->getParam('kaihuhang');
            $paramObj->bound_name           =        $this->getParam('bound_name');
            $paramObj->province             =        $this->getParam('province');
            $paramObj->city                 =        $this->getParam('city');
            $paramObj->area                 =        $this->getParam('area');
            $paramObj->bank_code            =        $this->getParam('bank_code');
            $paramObj->id_card              =        $this->getParam('id_card');
            $paramObj->token                =        $this->getParam('token');


        if(!empty($paramObj)){
            return $this->view('index.user_card')->with('info',$paramObj);
        }else{
            return $this->view('index.user_card');
        }

    }

    public function GetBankCode()
    {
        #收集信息
        $paramObj = new stdClass();
        $paramObj->bank_id              =        $this->getParam('bank_id');
        $paramObj->bank_num             =        $this->getParam('bank_num');
        $paramObj->bank_name            =        $this->getParam('bank_name');
        $paramObj->bound_mobile         =        $this->getParam('bound_mobile');
        $paramObj->kaihuhang            =        $this->getParam('kaihuhang');
        $paramObj->bound_name           =        $this->getParam('bound_name');
        $paramObj->province             =        $this->getParam('province');
        $paramObj->city                 =        $this->getParam('city');
        $paramObj->area                 =        $this->getParam('area');
        $paramObj->bank_code            =        $this->getParam('bank_code');
        $paramObj->id_card              =        $this->getParam('id_card');
        $paramObj->token                =        $this->getParam('token');
        $paramObj->v_id                 =        $this->getParam('v_id');


        $result = UserService::instance()->GetBankCode($paramObj);
        if($result['data']['resultCode']==000){
            return 1;
        }else{
            return $result['message'];die;
        }


    }




}








